﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LuZhouLaoJiao;
using MySql.Data.MySqlClient;
using System.IO;

using System.Data.SQLite;
//using Excel = Microsoft.Office.Interop.Excel;

namespace LuZhouLaoJiao
{
    public partial class BatchInfo : Form
    {
        public BatchInfo()
        {
            InitializeComponent();
        }

        //int pageSize = Global.pageSize;
        int pageSize = 0;
        int totalRows = 0;
        int pageCount = 0; //totalRows/pageSize
        int pageCurrent = 1;
        int RowCurrent = 0;

        public Boolean isAddRow = false;
        public string doublePiCi = null;
        public int doubleRow;
        public float avgAcidity = 0;
        public DataTable dt = null;
        //MySqlConnection conn = null;
        //MySqlCommand comm = null;
        //MySqlDataReader reader = null;

        SQLiteCommand comm = null;
        SQLiteConnection conn = null;
        SQLiteDataReader reader = null;
        //string strCon = null;
        //string dbUser = Global.getRegeditValue("localDBUser");
        //string dbPwd = Global.getRegeditValue("localDBPwd");
        //string database = Global.getRegeditValue("localDatabase");
        //string ip = Global.getRegeditValue("localIP");
        
        private void BatchInfo_Load(object sender, EventArgs e)
        {
            pageSize = (this.Height - 80) / dataGridView1.RowTemplate.Height;
            dataGridView1.Height = pageSize * dataGridView1.RowTemplate.Height;
            //MessageBox.Show(pageSize.ToString());
            lbLoginer.Text = "User: " + Global.userName;   
            //if (!Global.isKeyExist("FirstRunning"))
            //{
            //    if (!Global.isKeyExist("AlreadySetLocalDB"))
            //    {
            //        SetLocalDatabase localDB = new SetLocalDatabase();
            //        localDB.ShowDialog();
            //    }
            //    else
            //    {
            //        if (!Global.isKeyExist("AlreadySetRemoteDB"))
            //        {
            //            if (!Global.isKeyExist("AlreadyRunSetRemoteDB"))
            //            {
            //                SetRemoteDB remoteDB = new SetRemoteDB();
            //                remoteDB.ShowDialog();
            //            }
            //        }
            //        LoadData(pageCurrent, RowCurrent);
            //    }
            //}
            LoadData(pageCurrent, RowCurrent);
        }

        private void BatchInfo_SizeChanged(object sender, System.EventArgs e)
        {
            pageSize = (this.Height - 80) / dataGridView1.RowTemplate.Height;
            pageCount = (int)Math.Ceiling((double)(totalRows + 0.1) / pageSize);
            if (pageCount < pageCurrent)
            {
                RowCurrent = 0;
                pageCurrent = 1;
            }
            LoadData(pageCurrent, RowCurrent);
        }
        public void LoadData(int pCurrent, int rCurrent)
        {
            conn = new SQLiteConnection("Data Source=./data.db");
            comm = new SQLiteCommand();
            //MessageBox.Show("sqlite");
            conn.Open();
            comm = conn.CreateCommand();
            comm.CommandText = "select count(*) from batch_info;";

            totalRows = Convert.ToInt32(comm.ExecuteScalar());
            pageCount = (int)Math.Ceiling((double)(totalRows + 0.1) / pageSize);

            comm.CommandText = "select * from batch_info order by pici_id desc limit " + RowCurrent + "," + pageSize + ";";
            lbPageInfo.Text = "共" + pageCount + "页， 当前第" + pageCurrent + "页";
            try
            {

                reader = comm.ExecuteReader();
                dt = new DataTable();
                dt.Load(reader);

                dt.Columns[0].ColumnName = "批次号";
                dt.Columns[1].ColumnName = "平均酸度";
                dt.Columns[2].ColumnName = "检测人";
                dt.Columns[3].ColumnName = "样本来源";
                dt.Columns[4].ColumnName = "检测日期";
                dt.Columns[5].ColumnName = "检测时间";
                dt.Columns[6].ColumnName = "备注";
                dt.Columns[7].ColumnName = "已提交";

                dataGridView1.DataSource = dt;
                dataGridView1.Columns[0].ReadOnly = true;
                dataGridView1.Columns[0].Width = 120;
                dataGridView1.Columns[1].ReadOnly = true;
                dataGridView1.Columns[2].ReadOnly = true;
                dataGridView1.Columns[4].ReadOnly = true;
                dataGridView1.Columns[5].ReadOnly = true;


                //this.Width = 780;

            }
            
            catch (System.Exception ex)
            {
                //if(ex.GetType() == System.ArgumentOutOfRangeException)
                //MessageBox.Show(ex.GetType().ToString());
                if (!ex.GetType().ToString().Contains("ArgumentOutOfRangeException"))
                {
                    MessageBox.Show("数据库读取错误(BI1)：" + ex.Message);
                }
                    
            }
            finally
            {
                //reader.Close();
                //conn.Close();
            }

            //int i = Convert.ToInt32(comm.ExecuteScalar());
            //conn.Close();




            //strCon = "server = " + ip + "; user id = " + dbUser + "; password = " + dbPwd + "; database = " + database + "; persist security info = false";
            //conn = new MySqlConnection(strCon);
            //comm = new MySqlCommand();
            //comm.Connection = conn;
            //comm.CommandText = "select count(*) from batch_info;";
            //try
            //{
            //    conn.Open();
            //    totalRows = Convert.ToInt32(comm.ExecuteScalar());
            //    pageCount = (int)Math.Ceiling((double)(totalRows + 0.1) / pageSize);
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show("数据库读取错误(BI)：" + ex.Message);
            //}
            //comm.CommandText = "select * from batch_info order by pici_id desc limit " + RowCurrent + "," + pageSize + ";";
            //lbPageInfo.Text = "共" + pageCount + "页， 当前第" + pageCurrent + "页";
            //try
            //{

            //    reader = comm.ExecuteReader();
            //    dt = new DataTable();
            //    dt.Load(reader);

            //    dt.Columns[0].ColumnName = "批次号";
            //    dt.Columns[1].ColumnName = "平均酸度";
            //    dt.Columns[2].ColumnName = "检测人";
            //    dt.Columns[3].ColumnName = "样本来源";
            //    dt.Columns[4].ColumnName = "检测日期";
            //    dt.Columns[5].ColumnName = "检测时间";
            //    dt.Columns[6].ColumnName = "备注";

            //    dataGridView1.DataSource = dt;
            //    dataGridView1.Columns[0].ReadOnly = true;
            //    dataGridView1.Columns[0].Width = 120;
            //    dataGridView1.Columns[1].ReadOnly = true;

            //    //this.Width = 780;
                
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show("数据库读取错误(BI)：" + ex.Message);
            //}
            //finally
            //{
            //    //reader.Close();
            //    //conn.Close();
            //}
        }

        private void 新增批次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InputBatchDetails newBatch = new InputBatchDetails();
            newBatch.ShowDialog(this);
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        //当单元格退出编辑模式，如果修改了单元格值.
        private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            string header = dataGridView1.Columns[e.ColumnIndex].HeaderText;
            comm.CommandText = "update batch_info set " + Global.headerMatch(header) + " = '" + e.Value.ToString() + "' where pici_id = '" + dataGridView1[0, e.RowIndex].Value + "';";
            try
            {
                comm.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库更新值错误：" + ex.Message);
            }
        }

        private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            
            //MessageBox.Show(isAddRow.ToString());

            if (isAddRow)
            {
                string pici_id1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["批次号"].Value);
                string suandu1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["平均酸度"].Value);
                string jianceren1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["检测人"].Value);
                string laiyuan1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["样本来源"].Value);
                string riqi1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["检测日期"].Value);
                string shijian1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["检测时间"].Value);
                string beizhu1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["备注"].Value);
                string tijiao1 = Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells["已提交"].Value);
                
                if (suandu1 == "")
                {
                    comm.CommandText = "insert into batch_info values('" + pici_id1 + "',null,'" + jianceren1 + "','" + laiyuan1 + "','" + riqi1 + "','" + shijian1 + "','" + beizhu1 +"','" + tijiao1+ "');";
                    //MessageBox.Show(comm.CommandText);
                }
                else
                {
                    comm.CommandText = "insert into batch_info values('" + pici_id1 + "','" + suandu1 + "','" + jianceren1 + "','" + laiyuan1 + "','" + riqi1 + "','" + shijian1 + "','" + beizhu1 + "','" + tijiao1 +"');";
                    //MessageBox.Show(comm.CommandText);
                }
                try
                {
                    comm.ExecuteNonQuery();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("数据库插入行错误(BI)：" + ex.Message);
                }
                isAddRow = false;
                LoadData(0, 0);
            }
        }
        private void BatchInfo_FormClosed(Object sender, FormClosedEventArgs e)
        {
            reader.Close();
            conn.Close();

            //关闭应用程序的所有线程
            Application.Exit();
        }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //MessageBox.Show("#################");
            Global.inquiried = false;
            if (e.ColumnIndex == 0)
            {
                if (dataGridView1[1, e.RowIndex].Value.ToString().CompareTo("") == 0)
                {
                    //无值
                    doublePiCi = dataGridView1[0, e.RowIndex].Value.ToString();
                    doubleRow = e.RowIndex;
                    TestAcidity testAcidity = new TestAcidity();
                    testAcidity.ShowDialog(this);
                }
                else
                {
                    //有值
                    doublePiCi = dataGridView1[0, e.RowIndex].Value.ToString();
                    BatchDetailsInfo batchDetails = new BatchDetailsInfo();
                    batchDetails.ShowDialog(this);
                }
            }
            
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1[1, e.RowIndex].Value.ToString() == "")
            {
                MessageBox.Show("酸度值不能修改为空");
                return;
            }
            comm.CommandText = "update batch_info set suandu = '" + avgAcidity + "' where pici_id = '" + doublePiCi + "';";
            try
            {
                comm.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("无法写入平均酸度(BI)：" + ex.Message);
            }     
        }

        private void 本地数据库设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetLocalDatabase setLocal = new SetLocalDatabase();
            setLocal.ShowDialog();
        }

        private void 远程数据库设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetRemoteDB setRemote = new SetRemoteDB();
            setRemote.ShowDialog();
        }

        private void 输出到ExcelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("确定要将本页数据输出到Excel?", "输出数据到Excel", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Global.DataGridviewShowToExcel(dataGridView1, true);
                }
                else
                {
                    return;
                }
            }
            catch(System.Runtime.InteropServices.COMException)
            {
                MessageBox.Show("本机上没有Windows Office应用程序，无法使用此功能.");
            }
            
        }

        private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex >= 0)
            {
                if (dataGridView1[1, e.RowIndex].Value.ToString() != "")
                {
                    e.ToolTipText = "双击查看详细信息";
                }
                else
                {
                    e.ToolTipText = "双击进行样品检测";
                }   
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void 查询批次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InquiryInput search = new InquiryInput();
            search.ShowDialog(this);
        }

        private void 创建管理员账户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (isAdmin())
            {
                CreateAdminUser admin = new CreateAdminUser();
                admin.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有管理员账户才能创建账户.");
            }
        }

        private void 创建普通用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (isAdmin())
            {
                CreateNormalUser user = new CreateNormalUser();
                user.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有管理员账户才能创建账户.");
            }
        }

        private void 删除账户ToolStripMenuItem_Click(object sender, EventArgs e)
        {


            if (isAdmin())
            {
                DeleteUser deleteUser = new DeleteUser();
                deleteUser.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有管理员账户才能删除其他账户.");
            }
        }

        private bool isAdmin()
        {
            bool admin = false;
            comm.CommandText = "select * from user where name = '" + Global.userName + "' and isadmin = '1';";
            try
            {
                int i = Convert.ToInt32(comm.ExecuteScalar());
                if (i > 0)
                {
                    admin = true;
                }
                else
                {
                    admin = false;
                }
                return admin;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库读取错误(BI)：" + ex.Message);
                return false;
            }
            finally
            {
                //conn.Close();
            }
        }

        private void lbFirstPage_Click(object sender, EventArgs e)
        {
            if (pageCurrent == 1)
            {
                MessageBox.Show("已经是第一页.");
                return;
            }
            pageCurrent = 1;
            RowCurrent = 0;
            LoadData(pageCurrent, RowCurrent);
        }

        private void lbLastPage_Click(object sender, EventArgs e)
        {
            if (pageCurrent == 1)
            {
                MessageBox.Show("已经是第一页.");
                return;
            }
            pageCurrent--;
            RowCurrent = (pageCurrent - 1) * pageSize;

            LoadData(pageCurrent, RowCurrent);
        }

        private void lbNextPage_Click(object sender, EventArgs e)
        {
            if (pageCurrent == pageCount)
            {
                MessageBox.Show("已经到达最后一页.");
                return;
            }
            //if(pageCurrent >=)
            RowCurrent = pageCurrent * pageSize;
            pageCurrent++;
            LoadData(pageCurrent, RowCurrent);
        }

        private void lbFinalPage_Click(object sender, EventArgs e)
        {
            if (pageCurrent == pageCount)
            {
                MessageBox.Show("已经是最后一页.");
                return;
            }
            pageCurrent = pageCount;
            RowCurrent = (pageCurrent - 1) * pageSize;
            LoadData(pageCurrent, RowCurrent);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                pageCurrent = int.Parse(textBox1.Text.ToString());
                if (pageCurrent > pageCount)
                {
                    MessageBox.Show("输入页数太大.");
                    return;
                }
                else if (pageCurrent < 1)
                {
                    MessageBox.Show("输入页数太小.");
                    return;
                }
                RowCurrent = (pageCurrent - 1) * pageSize;
                LoadData(pageCurrent, RowCurrent);
            }
            catch (System.FormatException ex)
            {
                if (textBox1.Text.ToString() == "")
                    return;
                MessageBox.Show("只接受整数值.");
            }
        }

        private void 删除批次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //DeleteBatch deleteBatch = new DeleteBatch();
            //deleteBatch.ShowDialog();
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("您没有选中任何测试数据");
                return;
            }
            try
            {
                if (dataGridView1.CurrentRow.Index < 0)
                {
                    return;
                }
            }
            catch (System.NullReferenceException ex)
            {
                MessageBox.Show("您还没有选中任何测试数据.");
            }
            
            DialogResult result = MessageBox.Show("确定要删除批次" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "?", "删除批次", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                comm.CommandText = "delete from batch_info where pici_id = '" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "';";
                try
                {
                    int i = comm.ExecuteNonQuery();
                    if (i > 0)
                    {
                        MessageBox.Show("批次" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "已经被删除.");
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("删除批次出现错误(BI)" + ex.Message);
                }
                LoadData(pageCurrent, RowCurrent);
            }
        }

        private void 用户管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (isAdmin())
            {
                ManageUser mu = new ManageUser();
                mu.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有管理员才能使用此功能.");
            }
        }

        private void 提交toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("您没有选中任何测试数据");
                return;
            }
            if (dataGridView1.CurrentRow.Index < 0)
            {
                return;
            }
            if (!Global.isKeyExist("AlreadySetLocalDB"))
            {
                //MessageBox.Show("还没有设置到远程数据库的连接");
                DialogResult link = MessageBox.Show("还没有设置到远程数据库的连接,现在设置？", "设置数据库连接", MessageBoxButtons.YesNo);
                if (link == DialogResult.Yes)
                {
                    SetLocalDatabase localDB = new SetLocalDatabase();
                    localDB.ShowDialog();
                }
            }

            string dgvpici = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvsuandu = dataGridView1[1, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvjianceren = dataGridView1[2, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvlaiyuan = dataGridView1[3, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvriqi = dataGridView1[4, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvshijian = dataGridView1[5, dataGridView1.CurrentRow.Index].Value.ToString();
            string dgvbeizhu = dataGridView1[6, dataGridView1.CurrentRow.Index].Value.ToString();
            if (dgvsuandu == "")
            {
                MessageBox.Show("测试后才能提交.");
                return;
            }

            string dbUser = Global.getRegeditValue("localDBUser");
            string dbPwd = Global.getRegeditValue("localDBPwd");
            string database = Global.getRegeditValue("localDatabase");
            string ip = Global.getRegeditValue("localIP");
            string strCon = "server = " + ip + "; user id = " + dbUser + "; password = " + dbPwd + "; database = " + database + "; persist security info = false";
            //MessageBox.Show(strCon);
            MySqlConnection mysqlConn = new MySqlConnection(strCon);
            MySqlCommand mysqlComm = new MySqlCommand();
            mysqlComm.Connection = mysqlConn;
            //mysqlComm.CommandText = "insert into batch_info values('" + dgvpici + "','" + dgvsuandu + "','" + dgvjianceren + "','" + dgvlaiyuan + "','" + dgvriqi + "','" + dgvshijian + "','" + dgvbeizhu + "');";
            mysqlComm.CommandText = "select count(*) from batch_info where pici_id = '" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "';";
            try
            {
                mysqlConn.Open();

                int i = Convert.ToInt32(mysqlComm.ExecuteScalar());
                if (i > 0)
                {
                    //已存在
                    MessageBox.Show("该记录已提交过.");
                    return;
                }
                else
                {
                    //未提交
                    mysqlComm.CommandText = "insert into batch_info values('" + dgvpici + "','" + dgvsuandu + "','" + dgvjianceren + "','" + dgvlaiyuan + "','" + dgvriqi + "','" + dgvshijian + "','" + dgvbeizhu + "');";
                    mysqlComm.ExecuteNonQuery();

                    //sample中的字段
                    string yangben_s, pici_id_s, jiaochi_s, suandu_s, jiqi_s, shijian_s, laiyuan_s, beizhu_s;
                    comm.CommandText = "select * from sample where pici_id = '" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "';";
                    try
                    {
                        reader = comm.ExecuteReader();
                        while (reader.Read())
                        {
                            yangben_s = reader[1].ToString();
                            pici_id_s = reader[2].ToString();
                            jiaochi_s = reader[3].ToString();
                            suandu_s = reader[4].ToString();
                            jiqi_s = reader[5].ToString();
                            shijian_s = reader[6].ToString();
                            laiyuan_s = reader[7].ToString();
                            beizhu_s = reader[8].ToString();

                            //MessageBox.Show(yangben_s + pici_id_s+ jiaochi_s + suandu_s + jiqi_s + shijian_s + laiyuan_s + beizhu_s);
                            mysqlComm.CommandText = "insert into sample values(null, '" + yangben_s + "','" + pici_id_s + "','" + jiaochi_s + "','" + suandu_s + "','" + jiqi_s + "','" + shijian_s + "','" + laiyuan_s + "','" + beizhu_s + "');";
                            mysqlComm.ExecuteNonQuery();
                        }
                        if (!reader.IsClosed)
                        {
                            reader.Close();
                        }
                        
                        //设置已提交字段
                        comm.CommandText = "update batch_info set tijiao = '是' where pici_id = '" + dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString() + "';";
                        comm.ExecuteNonQuery();
                        LoadData(pageCurrent, RowCurrent);
                        
                        MessageBox.Show("已提交");
                    }
                    catch (System.Exception ex)
                    {
                        //MessageBox.Show("远程数据库写入错误(BI)" + ex.Message);
                        if (mysqlConn.State != ConnectionState.Open)
                        {
                            DialogResult link = MessageBox.Show("无法建立到远程数据库的连接,是否重新设置？", "设置数据库连接", MessageBoxButtons.YesNo);
                            if (link == DialogResult.Yes)
                            {
                                SetLocalDatabase localDB = new SetLocalDatabase();
                                localDB.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("远程数据库写入错误(BI)" + ex.Message);
                        }
                    }
                    finally
                    {
                        
                    }
                }
                
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("远程数据库写入错误(BI)：" + ex.Message);
            }
            finally
            {
                //mysqlConn.Close();
                reader.Close();
                mysqlConn.Close();
            }

            
        }

        private void 远程ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (isAdmin())
            {
                if (!Global.isKeyExist("AlreadySetLocalDB"))
                {
                    //MessageBox.Show("还没有设置到远程数据库的连接");
                    DialogResult link = MessageBox.Show("还没有设置到远程数据库的连接,现在设置？", "设置数据库连接", MessageBoxButtons.YesNo);
                    if (link == DialogResult.Yes)
                    {
                        SetLocalDatabase localDB = new SetLocalDatabase();
                        localDB.ShowDialog();
                    }
                    else
                    {
                        return;
                    }
                }
                RemoteBatchInfo rbi = new RemoteBatchInfo();
                rbi.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有管理员才能查看远程服务器上的数据.");
            }
        }
    }
}
